﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using BudgetManager.Resources;
using BudgetManager.Data;

namespace BudgetManager
{
    public partial class MainPage : PhoneApplicationPage
    {
        private BudgetMgrDAL budgetmanager = new BudgetMgrDAL();
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            txtAdd.Visibility = budgetmanager.LoadCategories().Count > 0 ? Visibility.Visible : Visibility.Collapsed;
            // Sample code to localize the ApplicationBar
            BuildLocalizedApplicationBar();
        }

        private void BuildLocalizedApplicationBar()
        {
            ApplicationBar = new ApplicationBar();

            // Create a new menu item with the localized string from AppResources.
            ApplicationBarMenuItem appBarMenuItem1 = new ApplicationBarMenuItem(AppResources.SettingsHeaderText);
            appBarMenuItem1.Click += settingsClicked;
            ApplicationBarMenuItem appBarMenuItem2 = new ApplicationBarMenuItem(AppResources.About);
            appBarMenuItem2.Click += AboutClicked;
            ApplicationBar.MenuItems.Add(appBarMenuItem1);
            ApplicationBar.MenuItems.Add(appBarMenuItem2);
        }

        #region EVENT_HANDLERS
        private void txtCategories_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/Categories.xaml"), UriKind.Relative));
        }

        private void addClicked(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/AddExpense.xaml"), UriKind.Relative));
        }

        private void reportsClicked(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/ExpenseReports.xaml"), UriKind.Relative));
        }

        private void settingsClicked(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/SettingsDetails.xaml"), UriKind.Relative));
        }

        private void AboutClicked(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/SettingsDetails.xaml?LandingPage=1"), UriKind.Relative));
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            txtAdd.Visibility = budgetmanager.LoadCategories().Count > 0 ? Visibility.Visible : Visibility.Collapsed;
        }
        #endregion
    }
}